<template>
    <h2>添加</h2>
    <div>
        <table>
            <tbody>
                <tr>
                    <td>姓名</td>
                    <td>
                        <input type="text" v-model="form.name">
                    </td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td>
                        <input type="password" v-model="form.pwd">
                    </td>
                </tr>
                <tr>
                    <td>性别</td>
                    <td>
                        <input type="text" v-model="form.sex">
                    </td>
                </tr>
                <tr>
                    <td>手机号</td>
                    <td>
                        <input type="text" v-model="form.phone">
                    </td>
                </tr>
                <tr>
                    <td>地址</td>
                    <td>
                        <input type="text" v-model="form.adder">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                       <button class="btn btn-primary" @click="add">添加</button>
                    </td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">
    //引入组件
import { ref, reactive, onMounted } from "vue"
//bootstrap样式
import "bootstrap/dist/css/bootstrap.min.css"
//访问后端
import axios from "axios"
//路由(1)
import { useRouter } from "vue-router";

const router = useRouter();

const form=reactive({
    id: 0,
  name: "",
  pwd: "",
  sex: "",
  phone: "",
  adder: ""
})

const add =()=>{
    if(!form.name){
        alert("名称不能为空");
        return;
    }
    if(!form.pwd){
        alert("密码不能为空");
        return;
    }
    axios.post("https://localhost:7237/api/User/AddUser",form).then(res=>{
        if(res.data>0){
            alert("添加成功！！");
            router.push("/workshow")
        }
        else
        {
            alert("添加失败");
        }
    })



}





</script>

<style scoped>

</style>